package com.example.demo2.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA
 * Description：添加拦截器
 * User：chenshu
 * Date：2023-12-31
 * Time：21:27
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1、自己new
        //registry.addInterceptor(new LoginInterceptor());
        //2、交给Spring去托管
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns("/user/login")//排除不拦截的url
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/*.ico");
    }
}
